package cn.learn.async.unsafe;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * JUC安全类型的集合
 *
 * @author huangyezhan
 * @version 1.0
 * @date 2021年05月30日19:42
 */
public class TestJUC {

    public static void main(String[] args) {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 100000; i++) {
            new Thread(() -> {
                list.add(Thread.currentThread().getName());
            }).start();
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());
    }

}
